home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17785 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  66 lines

  1. Path: cs.tu-berlin.de!news
  2. From: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: 'chained': It would be nice if...
  5. Date: Wed, 17 Apr 1996 16:53:26 +0200
  6. Organization: Technical University of Berlin
  7. Message-ID: <317505E6.7F7F@cs.tu-berlin.de>
  8. References: <31756DEC.5215@zurich.ibm.com>
  9. NNTP-Posting-Host: 130.149.17.230
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (Win95; I)
  14.  
  15. Keith Whittingham wrote:
  16. > Three or four times I've find myself needing a construct which I
  17. > think is missing from C++ (or at least is inaccessable).
  18. > A keyword, say 'chained', to have a similar effect to that of
  19. > the virtual destructor. e.g.
  20. > class Base
  21. >   {
  22. >   public:
  23. >     virtual void vMember(void);
  24. >     chained void cMember(void);
  25. >   };
  26. > class Derived:
  27. >   public Base
  28. >   {
  29. >   public:
  30. >     void vMember(void);
  31. >     void cMember(void);
  32. >   };
  33. > Calling Derived::vMember() executes the code contained in the body
  34. > Derived::vMember() whereas calling Derived::cMember() would
  35. > execute the code contained in the body Base::cMember() and then
  36. > the code contained in Derived::cMember().
  37.  
  38. How about:
  39.  
  40. class Base
  41. {
  42. public:
  43.  void    cMember(void)
  44.     {
  45.      Base_cMember();
  46.      Derived_cMember();
  47.     }
  48. protected:
  49.  virtual void    Derived_cMember();
  50. private:
  51.  void    Base_cMember();
  52. };
  53.  
  54. Every time cMember is called the unique private code in Base_cMember is 
  55. executed. Then Derived_cMember is called which can be overridden in derived 
  56. classes.
  57.  
  58. Bye
  59.  
  60. Roman
  61.